home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 1
/
Nebula One.iso
/
Misc
/
SciCalc1.1
/
Source
/
fmttst.c
< prev
next >
Wrap
Text File
|
1994-04-24
|
2KB
|
95 lines
#import <string.h> /* Standard C string operator function prototypes */
#include <stdio.h> /* Standard I/O functions and definitions */
#include <math.h> /* Standard C math library function prototypes */
void STR_OctalToBinary (char*, char*);
void STR_BinaryToOctal (char*, char*);
int main()
{ /* Local Variables */
double quadword;
float flword;
long ilword, *ilwptr;
short word;
int fmtlen;
char byte;
char fmtstr[128];
char outstr[128];
char *fmtptr;
printf("Enter Quadword Value: ");
scanf("%lf",&quadword);
printf("%f\n", quadword);
printf("Enter Longword Value: ");
scanf("%x",&ilword);
printf("%X\n", ilword);
printf("Enter Word Value: ");
scanf("%hx",&word);
printf("%X\n", word);
printf("Enter Byte Value: ");
scanf("%hx",(short*)&byte);
printf("%X\n", byte);
printf("Enter Format Length: ");
scanf("%d", &fmtlen);
flword = quadword;
ilword = quadword;
ilwptr = (long*) &quadword;
word = quadword;
byte = quadword;
printf("DECIMAL:\n");
printf("\tfmtlen:%.*f\n", fmtlen,quadword);
printf("\tquadword:%f\n", quadword);
printf("\tlongword:%f\n", flword);
printf("\tword :%d\n", word);
printf("\tbyte :%d\n", byte);
#if 0
printf("HEXIDECIMAL:\n");
printf("\tquadword:%8.8X,%8.8X\n", *ilwptr,*(ilwptr+1));
printf("\tlongword:%8.8X\n", ilword);
printf("\tword :%4.4X\n", (unsigned short) word);
printf("\tbyte :%2.2X\n", (unsigned char) byte);
printf("OCTAL:\n");
printf("\tquadword:%11.11o,%11.11o\n", *ilwptr,*(ilwptr+1));
printf("\tlongword:%11.11o\n", ilword);
printf("\tword :%6.6o\n", (unsigned short) word);
printf("\tbyte :%3.3o\n", (unsigned char) byte);
printf("BINARY:\n");
sprintf(fmtstr,"%11.11o%11.11o", *ilwptr,*(ilwptr+1));
STR_OctalToBinary (fmtstr, outstr);
printf("\tquadword:%s\n", outstr);
STR_BinaryToOctal (outstr, fmtstr);
printf("\t :(%s)\n", fmtstr);
sprintf(fmtstr, "%11.11o", ilword);
STR_OctalToBinary (fmtstr, outstr);
printf("\tlongword:%s\n", outstr);
STR_BinaryToOctal (outstr, fmtstr);
printf("\t :(%s)\n", fmtstr);
sprintf(fmtstr, "%6.6o", (unsigned short) word);
STR_OctalToBinary (fmtstr, outstr);
printf("\tword :%s\n", outstr);
STR_BinaryToOctal (outstr, fmtstr);
printf("\t :(%s)\n", fmtstr);
sprintf(fmtstr, "%3.3o", (unsigned char) byte);
STR_OctalToBinary (fmtstr, outstr);
printf("\tbyte :%s\n", outstr);
STR_BinaryToOctal (outstr, fmtstr);
printf("\t :(%s)\n", fmtstr);
#endif
return 0;
}